import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * industryCategory - 国标品类定义 - model
 * @date: 2018-7-24
 */
import { getResponse } from 'utils/utils';
import { queryTopCategory, querySecondCategory, queryCategory, saveIndustry, saveCategory, putIndustry, putCategory } from "../services/industryCategoryService";
export default {
  namespace: 'industryCategory',
  state: {
    topData: [],
    secondData: [],
    categoryData: []
  },
  effects: {
    fetchTopCategory: /*#__PURE__*/_regeneratorRuntime.mark(function fetchTopCategory(_ref, _ref2) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function fetchTopCategory$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call;
              _context.next = 4;
              return call(queryTopCategory, payload);

            case 4:
              response = _context.sent;
              return _context.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context.stop();
          }
        }
      }, fetchTopCategory);
    }),
    fetchSecondCategory: /*#__PURE__*/_regeneratorRuntime.mark(function fetchSecondCategory(_ref3, _ref4) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function fetchSecondCategory$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(querySecondCategory, payload);

            case 4:
              response = _context2.sent;
              return _context2.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchSecondCategory);
    }),
    fetchCategory: /*#__PURE__*/_regeneratorRuntime.mark(function fetchCategory(_ref5, _ref6) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function fetchCategory$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;
              _context3.next = 4;
              return call(queryCategory, payload);

            case 4:
              response = _context3.sent;
              return _context3.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchCategory);
    }),
    addIndustry: /*#__PURE__*/_regeneratorRuntime.mark(function addIndustry(_ref7, _ref8) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function addIndustry$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(saveIndustry, payload);

            case 4:
              response = _context4.sent;
              return _context4.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, addIndustry);
    }),
    addCategory: /*#__PURE__*/_regeneratorRuntime.mark(function addCategory(_ref9, _ref10) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function addCategory$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call;
              _context5.next = 4;
              return call(saveCategory, payload);

            case 4:
              response = _context5.sent;
              return _context5.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, addCategory);
    }),
    updateIndustry: /*#__PURE__*/_regeneratorRuntime.mark(function updateIndustry(_ref11, _ref12) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function updateIndustry$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call;
              _context6.next = 4;
              return call(putIndustry, payload);

            case 4:
              response = _context6.sent;
              return _context6.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, updateIndustry);
    }),
    updateCategory: /*#__PURE__*/_regeneratorRuntime.mark(function updateCategory(_ref13, _ref14) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function updateCategory$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref13.payload;
              call = _ref14.call;
              _context7.next = 4;
              return call(putCategory, payload);

            case 4:
              response = _context7.sent;
              return _context7.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, updateCategory);
    })
  },
  reducers: {
    queryTopCategory: function queryTopCategory(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        topData: action.payload
      });
    },
    querySecondCategory: function querySecondCategory(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        secondData: action.payload
      });
    },
    queryCategory: function queryCategory(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        categoryData: action.payload
      });
    },
    clearCategory: function clearCategory(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        categoryData: action.payload
      });
    }
  }
};